package com.leyou.item.service.controller;

import com.leyou.common.bean.Result;
import com.leyou.item.inter.dto.SpecSelectDTO;
import com.leyou.item.inter.pojo.SpecGroup;
import com.leyou.item.inter.pojo.SpecParam;
import com.leyou.item.service.service.SpecGroupParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zqq
 * @ClassName SpecGroupParamController
 * @Description
 * @date 2020/3/7-9:31
 */
@Api(value = "SpecGroupParamController",description = "商品规格接口")
@RestController
@RequestMapping("spec")
public class SpecGroupParamController {

    @Autowired
    private SpecGroupParamService specGroupParamService;

    @GetMapping("groups/{cid}")
    @ApiOperation(value = "根据分类id查询分组", notes = "根据分类id查询分组")
    public Result<List<SpecGroup>> queryGroupsByCid(@ApiParam(name = "cid",value = "商品分类id",required = true) @PathVariable("cid")Long cid){
        return this.specGroupParamService.queryGroupsByCid(cid);
    }

    @PostMapping("params")
    @ApiOperation(value = "根据规格参数条件查询规格参数", notes = "根据规格参数条件查询规格参数")
    public Result<List<SpecParam>> queryParams(@RequestBody SpecSelectDTO dto){
        return this.specGroupParamService.queryParams(dto);
    }

    @GetMapping("group/param/{cid}")
    @ApiOperation(value = "查询规格参数组，及组内参数", notes = "查询规格参数组，及组内参数")
    public Result<List<SpecGroup>> queryGroupsWithParam(@ApiParam(name = "cid",value = "商品分类id",required = true) @PathVariable("cid") Long cid){
        return this.specGroupParamService.queryGroupsWithParam(cid);
    }

    @PostMapping("group")
    @ApiOperation(value = "新增规格组", notes = "新增规格组")
    public Result saveGroup(@RequestBody SpecGroup dto){
        return this.specGroupParamService.saveSepcGroup(dto);
    }

    @PutMapping("group")
    @ApiOperation(value = "修改规格组", notes = "修改规格组")
    public Result updateGroup(@RequestBody SpecGroup dto){
        return this.specGroupParamService.updateSepcGroup(dto);
    }

    @DeleteMapping("group/{id}")
    @ApiOperation(value = "删除规格组", notes = "删除规格组")
    public Result deleteGroup(@ApiParam(name = "id",value = "规格组id",required = true) @PathVariable("id") Long id){
        return this.specGroupParamService.deleteSepcGroup(id);
    }

    @PostMapping("param")
    @ApiOperation(value = "新增规格参数", notes = "新增规格参数")
    public Result saveParam(@RequestBody SpecParam dto){
        return this.specGroupParamService.saveSpecParam(dto);
    }

    @PutMapping("param")
    @ApiOperation(value = "修改规格参数", notes = "修改规格参数")
    public Result updateParam(@RequestBody SpecParam dto){
        return this.specGroupParamService.updateSpecParam(dto);
    }

    @DeleteMapping("param/{id}")
    @ApiOperation(value = "删除规格参数", notes = "删除规格参数")
    public Result deleteParam(@ApiParam(name = "id",value = "规格参数id",required = true) @PathVariable("id") Long id){
        return this.specGroupParamService.deleteSpecParam(id);
    }

}
